package v1

import (
	"encoding/json"
	"fmt"
	"gohub/app/mock"
	"gohub/app/services"
	"gohub/pkg/response"

	"github.com/gin-gonic/gin"
)

type ChartController struct {
	BaseAPIController
}

// Index 所有
func (ctrl *ChartController) Trend(c *gin.Context) {
	data, _ := services.GetTrend()
	response.Data(c, data)
}

func (ctrl *ChartController) Amount(c *gin.Context) {
	data, _ := services.GetAmount()
	response.Data(c, data)
}

func (ctrl *ChartController) Calendar(c *gin.Context) {
	data, _ := services.GetCalendar()
	response.Data(c, data)
}

func (ctrl *ChartController) Pie(c *gin.Context) {
	data, _ := services.GetPie(c)
	response.Data(c, data)
}

func (ctrl *ChartController) Wordcloud(c *gin.Context) {
	var result Response
	err := json.Unmarshal([]byte(mock.WordcloudJson), &result)
	if err != nil {
		fmt.Println(err.Error())
	}
	response.Data(c, result.Data)
}

type Response struct {
	Success bool        `json:"success"`
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}

func (ctrl *ChartController) Bmap(c *gin.Context) {
	var result Response
	err := json.Unmarshal([]byte(mock.BmapJson), &result)
	if err != nil {
		fmt.Println(err.Error())
	}

	response.Data(c, result.Data)
}

func (ctrl *ChartController) Regions(c *gin.Context) {
	var result Response
	err := json.Unmarshal([]byte(mock.RegionsJson), &result)
	if err != nil {
		fmt.Println(err.Error())
	}

	response.Data(c, result.Data)
}

func (ctrl *ChartController) Sheets(c *gin.Context) {
	var result Response
	err := json.Unmarshal([]byte(mock.SheetsJson), &result)
	if err != nil {
		fmt.Println(err.Error())
	}

	response.Data(c, result.Data)
}
